import { RoutesDataItem } from "@/utils/routes";
import {asyncRouterHandle} from '@/utils/asyncRouter'

/**
 * 获取本地路由
 */
export const getRouters = async (): Promise<Array<RoutesDataItem> | null> => {
	let routes: string | null = await localStorage.getItem("G-router");
	if (routes) {
			return asyncRouterHandle(routes)
	} else {
		return null;
	}
};

/**
 * 设置存储本地路由
 */
export const setRouters = async (routers: Array<RoutesDataItem>): Promise<boolean> => {
	try {
		await localStorage.setItem("G-router", routers);
		return true;
	} catch (error) {
		return false;
	}
};

/**
 * 移除本地路由
 */
export const removeRouters = async (): Promise<boolean> => {
	try {
		await localforage.removeItem('routers');
		return true;
	} catch (error) {
		return false;
	}
};